#include <QtGui>
#include "infoview.h"

InfoView::InfoView(QWidget* parent):
	QWidget(parent)
{
  int i;

  for(i=0;i<256;i++){
    m_red[i]=255;
    m_green[i]=255;
    m_blue[i]=255;
  }
}

void InfoView::drawHist(int* red, int* green, int* blue)
{
  int i;

  for(i=0;i<256;i++){
    m_red[i]=red[i];
    m_green[i]=green[i];
    m_blue[i]=blue[i];
  }
  repaint();
}

void InfoView::paintEvent(QPaintEvent* event)
{
  QPainter painter(this);
  int i;
  double xfac,yfac;

  xfac = (double)width()/256.;
  yfac = (double)height()/256.;
  painter.setRenderHint(QPainter::Antialiasing);
  painter.setPen(QColor(255,0,0));
  for(i=1;i<256;i++)
    painter.drawLine((i-1)*xfac,m_red[i-1]*yfac,
		     i*xfac,m_red[i]*yfac);
  painter.setPen(QColor(0,255,0));
  for(i=1;i<256;i++)
    painter.drawLine((i-1)*xfac,m_green[i-1]*yfac,
		     i*xfac,m_green[i]*yfac);
  painter.setPen(QColor(0,0,255));
  for(i=1;i<256;i++)
    painter.drawLine((i-1)*xfac,m_blue[i-1]*yfac,
		     i*xfac,m_blue[i]*yfac);

}
